<template>
  <div>
    <input type="text" v-model='name'>
      <button @click='send'>发送</button>

  </div>
</template>
<script>

  export default {
    data(){
      return{
        name:''
      }
    },
    methods: {
      initWebSocket() {
        var socket = new WebSocket("ws:127.0.0.1:5000");
        //建立连接
        socket.onopen = function () {
          console.log('成功连接');//成功连接上Websocket
          setInterval(()=>{
            socket.send('23425454')
          },1000)

        };

        socket.onmessage =  (e=>{
          // var data = JSON.parse(e.data)
          console.log("***")
          console.log(e.data)
        });

        socket.onclose=function(e){
          console.log(e);
          console.log("close关闭")
          socket.close(); //关闭TCP连接
        };


      },
    },
    mounted() {
      this.initWebSocket()
    },
  }
  </script>
  <style lang="">

  </style>